Automatic linux login using RSA key pairs

chris (2005-02-03 12:21:47)
3978 views
0 replies
This is the process you need to go through to enable password-free logins between two ssh endpoints. In this example there are 2 servers - one called fred (that the machine the user wants to connect from) and another called barney (the destination host). For this example, we assume both machines are running Linux, or a similar flavour of unix.

# first generate an RSA key pair on the client machine, fred. This will create some new files under ~/.ssh/

ssh-keygen -t rsa

# now copy the public key file up to the host machine (barney) and put it into the .ssh folder in
# the user's home directory at the other end.

scp ~/.ssh/id_rsa.pub barney:~/.

then log into the remote machine in the usual way and move the new key file into place

# create the .ssh directory if it doesn't already exist

mkdir ~/.ssh

# copy the public key into ~/.ssh/authorized_keys

cat id_rsa.pub >> ~/.ssh/authorized_keys

# create a symbolic link to another file called authorized_keys2 to enable these keys for ssh2

# ln -s authorized_keys authorized_keys2

That's all that needs to be done. In fact this id_rsa.pub file can be appended to the authorized_keys file in any user's .ssh directory on any machine and the logins from that point will be totall seamless. This is very useful for automated scripts which use ssh or scp.


christo

comment